package rmi.eventing.types;

import java.text.SimpleDateFormat;

import rmi.eventing.types.AuctionEvent.Type;

/**
 * 
 * USER_LOGIN USER_LOGOUT USER_DISCONNECTED Events
 *
 */

public class UserEvent extends Event {
	private String userName="";
	public UserEvent(String userName){
		super();
		ID = "AC"+idCounter;
		this.userName=userName;
	}
	public void setType (Type type){
		this.type=type.getValue();
	}
	public enum Type{
		USER_LOGIN("USER_LOGIN"), USER_LOGOUT("USER_LOGOUT"),USER_DISCONNECTED("USER_DISCONNECTED");
		
		private String type;
		Type(String type){
			this.type = type;
		}
		public String getValue()
		{      
		      return type ;
		}
	}
	
	public String toString(){
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss z");
		String date = dateFormat.format(timestamp);
		if(type.equals("USER_LOGIN")){
			return "USER_LOGIN: "+date+" - user "+userName+" logged in";
		}
		else if(type.equals("USER_LOGOUT")){
			return "USER_LOGOUT: "+date+" - user "+userName+" logged out";
		}
		else if (type.equals("USER_DISCONNECTED")){
			return "USER_DISCONNECTED: "+date+" - user "+userName+" disconnected";
		}
	
		return "USER_EVENT: No type set";
	}
	//Username
	public String getUsername(){
		return userName;
	}
}
